(use-modules (gnu packages emacs)
             (gnu packages emacs-xyz)
             (gnu packages tex)
             (gnu packages texinfo)
             ((guix licenses) #:prefix license:)
             (guix build-system gnu)
             (guix packages)
             (guix git-download))

(define-public emacs-forge
  (let ((commit "3cfc0021bc4fd2496541a8600e1846ea144e99bc"))
    (package
      (name "emacs-forge")
      (version (git-version "0.0.1" "1" commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/magit/forge.git")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32
           "14yr3i7hm80r8799r3p1ijl117dzcs9m935g4k54ak3d1bb268al"))))
      (build-system gnu-build-system)
      (native-inputs
       `(("emacso" ,emacs-minimal)
         ("texlive" ,texlive) ;for texi2dvi
         ("texinfo" ,texinfo)))
      (propagated-inputs
       `(("emacs-closql" ,emacs-closql)
         ("emacs-dash" ,emacs-dash)
         ("emacs-emacsql" ,emacs-emacsql)
         ("emacs-ghub" ,emacs-ghub)
         ("emacs-let-alist" ,emacs-let-alist)
         ("emacs-magit" ,emacs-magit)
         ("emacs-markdown-mode" ,emacs-markdown-mode)
         ("emacs-transient" ,emacs-transient)))
      (arguments
       `(#:tests? #f ; there are no tests
         #:modules ((guix build gnu-build-system)
                    ((guix build emacs-build-system) #:prefix emacs:)
                    (guix build utils)
                    (guix build emacs-utils))
         #:imported-modules (,@%gnu-build-system-modules
                             (guix build emacs-build-system)
                             (guix build emacs-utils))
         #:phases
           (modify-phases %standard-phases
             (delete 'configure)
             (replace 'install
               (lambda* (#:key outputs #:allow-other-keys)
                 (install-file "docs/forge.info"
                               (string-append (assoc-ref outputs "out")
                                              "/share/info"))))

             ;; Build emacs side using 'emacs-build-system'.
             (add-after 'unpack  'emacs-set-emacs-load-path
               (assoc-ref emacs:%standard-phases 'set-emacs-load-path))
             (add-after 'compress-documentation 'enter-lisp-dir
               (lambda _
                 (chdir "lisp")
                 #t))
             (add-after 'enter-lisp-dir 'emacs-install
               (assoc-ref emacs:%standard-phases 'install)))))
      (home-page "https://github.com/magit/forge/")
      (synopsis "Access Git forges from Magit.")
      (description
       "Work with Git forges, such as Github and Gitlab, from the comfort
of Magit and the rest of Emacs.

The schema of the database has not been finalized yet.  Until that
has happened it will occationally have to be discarded.  For now
the database does not contain any information that cannot simply
be fetched again.
")
      (license license:gpl3+))))

emacs-forge
